package org.example.sec08.validator;


import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.protobuf.ProtoUtils;
import org.example.sec08.BankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Optional;

/**
 * @author Administrator
 */
public class RequestValidator {
    private static final Logger log = LoggerFactory.getLogger(RequestValidator.class);

    public static Optional<Status> validateAccount(int accountNumber) {
        if (accountNumber > 0 && accountNumber < 11) {
            return Optional.empty();
        }
        return Optional.of(Status.INVALID_ARGUMENT.withDescription("account number should be between 1 and 10"));
    }

    public static Optional<Status> isAmountDivisibleBy10(int amount) {
        if (amount > 0 && amount % 10 == 0) {
            return Optional.empty();
        }
        return Optional.of(Status.INVALID_ARGUMENT.withDescription("request amount should by 10 multiples"));
    }

    public static Optional<Status> hasSufficientBalance(int amount, int balance) {
        if (amount <= balance) {
            return Optional.empty();
        }
        return Optional.of(Status.FAILED_PRECONDITION.withDescription("insufficient balance"));
    }


}
